<template>
	<view>
		<view class="search_input">
			<view class="uni-form-item uni-column">
				<input v-model="movieSearchData.movieValue" class="uni-input" confirm-type="search" placeholder="请输入影视名" @confirm="searchConfirm"/>
			</view>
		</view>
		
		<view class="movie_content">
			<view v-for="(item, index) in movieDatas" :key="index" class="movie">
				<view class="movie_list" @click="movieDetail(item)">
					<view>
						<image style="width: 120px;height: 150px;" :src="item.imgHref"></image>
					</view>
					<view class="movie_name">
						<text>{{ item.movieName }}</text>
					</view>
					<view class="movie_update">
						<text>{{ item.movieUpdate }}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data () {
			return {
				movieSearchData: {
					movieValue: ''
				},
				movieDatas: []
			}
		},
		methods: {
			// 搜索框确定提交按钮
			searchConfirm() {
				uni.showLoading({
					title: '查询中,请耐心等待一下!',
					mask: true
				})
				const _that = this
				// 调用后台接口
				_that.$api.get({
					url: '/app/movie/search/list',
					params: {
						param: _that.movieSearchData.movieValue
					}
				}).then(res => {
					// console.log('res', res);
					if (res && res.data.code === 200) {
						_that.movieDatas = res.data.list
					}
					uni.hideLoading()
				}).catch(error => {
					console.log('fail:', error)
					uni.hideLoading()
				})
			},
			// 点击查看详情
			movieDetail(data) {
				let params = encodeURIComponent(JSON.stringify(data))
				uni.navigateTo({
					url: '/pages/movies/play-movie?params=' + params
				});
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #d8d9da;
	}
	.search_input {
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		margin-left: 10rpx;
		margin-right: 10rpx;
		background: #ffffff;
	}
	
	.movie {
		margin: 10rpx 10rpx 0 10rpx;
	}
	
	.movie_list {
		float: left;
		width: 50%;
	}
	
	.movie_name {
		display: flex;
		width: 300rpx;
		justify-content: center;
	}
	
	.movie_update {
		display: flex;
		width: 300rpx;
		justify-content: center;
	}
</style>